package com.dq.domain.reward;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.sys.section.SysSection;
import com.dq.domain.sys.user.user.StaffUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;

/**
 * @Author luchangtong
 * @Date 2019/11/20 15:12
 */
@Data
@Entity
@ApiModel("专项/随机奖励")
public class Reward extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("类别（专项/随机）")
    @Enumerated(EnumType.ORDINAL)
    protected RewardCategory rewardCategory;
    @ApiModelProperty(value = "门店",hidden = true)
    @ManyToOne
    protected SysSection org;
    @ApiModelProperty(value = "员工",hidden = true)
    @ManyToOne
    protected StaffUser staffUser;
    @ApiModelProperty("金额")
    protected BigDecimal rewardPrice;
    @ApiModelProperty("奖励备注")
    protected String remark;

    public enum RewardCategory{
        special("专项"),
        random("随机");
        String name;
        RewardCategory(String name){ this.name = name;}
    }

    @Data
    @ApiModel(value = "专项/随机奖励视图")
    public static class Vo implements VO {
        @ApiModelProperty("专项奖励id")
        protected Long id;
        @ApiModelProperty("专项奖励类别名称")
        protected String rewardCateName;
        protected RewardCategory rewardCateNameEn;
        protected Long orgId;
        @ApiModelProperty("专项奖励门店名称")
        protected String orgName;
        protected Long staffUserId;
        @ApiModelProperty("专项奖励用户名称")
        protected String userName;
        @ApiModelProperty("员工工号")
        protected String userCardNo;
        @ApiModelProperty("专项奖励金额")
        protected BigDecimal rewardPrice;
        @ApiModelProperty("奖励备注")
        protected String remark;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;
    }


    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.rewardCateName = fmt(this.getRewardCategory().name);
        vo.rewardCateNameEn = this.getRewardCategory();
        vo.orgId = this.getOrg().getId();
        vo.orgName = fmt(this.getOrg().getSimpleName());
        vo.staffUserId = fmt(this.staffUser.getId());
        vo.userName =fmt(this.staffUser.getUserRealcName());
        vo.userCardNo = fmt(this.staffUser.getCardNo());
        vo.rewardPrice = fmt(this.getRewardPrice());
        vo.remark = fmt(this.getRemark());
        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUsername();
        return vo;
    }
}
